﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSS_XNA.Engine.Error;

namespace DSS_XNA.Engine.Phyics
{
    public class BoundingBox
    {
        #region Properties

        public float X
        {
            get { return _x; }
            set { _x = value; }
        }
        private float _x = 0.0f;

        public float Y
        {
            get { return _y; }
            set { _y = value; }
        }
        private float _y = 0.0f;

        public float Width
        {
            get { return _width; }
            set { _width = value; }
        }
        private float _width = 0.0f;

        public float Height
        {
            get { return _height; }
            set { _height = value; }
        }
        private float _height = 0.0f;

        #endregion

        #region Public Methods

        public BoundingBox()
        {
        }

        public BoundingBox(float x, float y, float width, float height)
        {
            this._x = x;
            this._y = y;
            this._width = width;
            this._height = height;
        }

        public bool Collides(BoundingBox box)
        {
            if (box == null)
                throw new DSSException("'box' is null.");

            float left1, left2;
            float right1, right2;
            float top1, top2;
            float bottom1, bottom2;

            left1 = this.X;
            left2 = box.X;
            right1 = left1 + this.Width;
            right2 = left2 + box.Width;
            top1 = this.Y;
            top2 = box.Y;
            bottom1 = top1 + this.Height;
            bottom2 = top2 + box.Height;

            if (bottom1 < top2) return false;
            if (top1 > bottom2) return false;

            if (right1 < left2) return false;
            if (left1 > right2) return false;

            return true;
        }


        #endregion
    }
}
